import 'dart:ui';

import 'package:date_format/date_format.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/commom/Global.dart';
import 'package:percent_indicator/percent_indicator.dart';

import 'HYSizeFit.dart';
import 'ReleasePdItems.dart';

class ReleasePjItems extends StatefulWidget {
  ReleasePjItems({
    Key key,
  }) : super(key: key);
  @override
  State<StatefulWidget> createState(){
    return ReleasePjItemsState();
  }
}
class ReleasePjItemsState extends State<ReleasePjItems> {

  Widget _item_CardBuilder(BuildContext context, int position) {
    return GestureDetector(
      child: Container(
          color: Colors.white,
          margin: EdgeInsets.only(top: HYSizeFit.setPx(10)),
          child: Padding(
              padding: EdgeInsets.all(HYSizeFit.setPx(10)),
              child: IntrinsicHeight(
                child: Flex(
                  direction: Axis.horizontal,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment:MainAxisAlignment.spaceEvenly,
                  children: [
                    Expanded(
                      flex: 1,
                      child: Column(
                        mainAxisAlignment:MainAxisAlignment.spaceEvenly,
                        crossAxisAlignment:CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              Text(
                                Global.findUserProjects.projects[position]['pjName'],
                                style: TextStyle(
                                    fontSize: HYSizeFit.setPx(20),
                                    fontWeight: FontWeight.bold,
                                    color: Colors.black54
                                ),
                              )
                            ],
                          ),
                          Row(
                            mainAxisAlignment:MainAxisAlignment.end,
                            children: [
                              Text(
                                "状态：" + Global.findUserProjects.projects[position]['pjStatusTxt'],
                                style: TextStyle(
                                    fontSize: HYSizeFit.setPx(15),
                                    fontWeight: FontWeight.normal,
                                    color: Colors.black54
                                ),
                              )
                            ],
                          ),
                          Padding(padding: EdgeInsets.only(top: HYSizeFit.setPx(10))),
                          Text(
                            "发布日期：" + formatDate(Global.findUserProjects.projects[position]['pjProtime'], [yyyy, '-', mm, '-', dd]),
                            style: TextStyle(
                              fontSize: HYSizeFit.setPx(12),
                              color: Colors.black45,
                            ),
                          ),
                          Text(
                            "交期：" + formatDate(Global.findUserProjects.projects[position]['pjDeltime'], [yyyy, '-', mm, '-', dd]),
                            style: TextStyle(
                              fontSize: HYSizeFit.setPx(12),
                              color: Colors.black45,
                            ),
                          ),
                          Text(
                            "包揽情况：" + Global.findUserProjects.projects[position]['undertakeRate'],
                            style: TextStyle(
                              fontSize: HYSizeFit.setPx(12),
                              color: Colors.black45,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(padding: EdgeInsets.only(right: HYSizeFit.setPx(10))),
                    Expanded(
                      flex: 1,
                      child: Stack(
                        children: [
                          Column(
                            mainAxisAlignment:MainAxisAlignment.center,
                            crossAxisAlignment:CrossAxisAlignment.center,
                            children: [
                              Image.asset(
                                "imgs/gantt.png",
                              )
                            ],
                          ),
                          Positioned(
                              right: 0,
                              child: BackdropFilter(
                                filter: ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0),
                                child: Container(
                                  width: HYSizeFit.setPx(300),
                                  height: HYSizeFit.setPx(350),
                                  color: Colors.white10,
                                ),
                              )),
                          Column(
                            mainAxisAlignment:MainAxisAlignment.center,
                            crossAxisAlignment:CrossAxisAlignment.center,
                            children: [
                              Row(
                                mainAxisAlignment:MainAxisAlignment.center,
                                crossAxisAlignment:CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    width: HYSizeFit.setPx(150),
                                    height: HYSizeFit.setPx(25),
                                    child: Text(
                                      "进入查看项目甘特图",
                                      overflow: TextOverflow.ellipsis,
                                      maxLines: 3,
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black54,
                                          fontSize: HYSizeFit.setPx(15),
                                          fontWeight: FontWeight.bold
                                      ),
                                    ),
                                  )
                                ],
                              )
                            ],
                          )
                        ],
                      ),
                    )
                  ],
                ),
              )
          )),
      onTap: (){
        Navigator.push(
          context,
          new MaterialPageRoute(builder: (context) {
            return new ReleasePdItems(position:position);
          }),
        );
      },
    );

  }
  @override
  void initState() {}
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MediaQuery.removePadding(
      child: ListView.builder(
          padding: EdgeInsets.fromLTRB(HYSizeFit.setPx(10), 0, HYSizeFit.setPx(10), 10),
          itemCount: (Global.findUserProjects.projects == null)? 0 : Global.findUserProjects.projects.length,
          //itemExtent: HYSizeFit.setPx(150),
          shrinkWrap: true,
          //列表项构造器
          itemBuilder: _item_CardBuilder),
          removeTop: true,
          context: context,
    );
  }

}